import type { IBanner, INew, INewsList, IPicture, IPublicNew } from '@/types/news'
import type { IdType, IPage } from '@/types/table'

import { request } from '@/utils/request'


/**
 * 获取快讯列表
 * @param data 分页需要的当前页，每页几条数据
 * @returns 
 */
export const getNewsList = (data: IPage) =>
    request<INewsList>('/collegeNews','get',data)

/**
 * 获取快讯详情
 * @param id 
 * @returns 
 */
export const getOneNews = (id:number) => 
    request<INew>('/collegeNews/'+id,'get')

/**
 * 发布快讯
 * @param data 
 * @returns 
 */
export const publicNews = (data:IPublicNew) => 
    request<string>('/collegeNews','post',data)

/**
 * 编辑快讯文章
 * @param id 文章id
 * @param data 文章内容
 * @returns 
 */
export const editNews = (id:number,data:IPublicNew) =>
    request<string>('/collegeNews/'+id,'patch',data) 


/**
 * 删除快讯文章
 * @param id 
 * @returns 
 */
export const delNews = (id:number) => 
    request<IdType>('/collegeNews/'+id,'delete')

/**
 * 获取移动端首页轮播图列表
 * @returns 
 */
export const getBannerList = () => 
    request<IBanner>('/collegeNews/banner','get')

/**
 * 更新轮播图
 * @param id 图片id
 * @param data 图片地址
 * @returns 
 */
export const updatedBanner = (id:number,data:IPicture) =>
    request<string>('/collegeNews/banner/'+id,'patch',data) 
